package net.sky.oa.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 个人通讯录分组
 * AddGroup. @author hond
 */
@Entity
@Table(name = "ADD_GROUP")//个人通讯分组表
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class AddGroup implements Serializable {

	private static final long serialVersionUID = 5673991033245515351L;
	
	// Fields
	private Long id;
	private String name;   //分组名
	private Integer status;   //状态
	private SysEmployee user;//员工id
	
	private Set<AddMyaddr> myaddr = new HashSet<AddMyaddr>(0);

	// Constructors

	/** default constructor */
	public AddGroup() {}

	/** minimal constructor */
	public AddGroup(Long id) {
		this.id = id;
	}
	
	@Id 
	@SequenceGenerator(name="SQ_ADDGROUP_ID",sequenceName="SQ_ADDGROUP_ID",allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SQ_ADDGROUP_ID")
	@Column(name = "ID", unique = true, nullable = false)	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "NAME", length = 20)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "STATUS", precision = 2, scale = 0)
	public Integer getStatus() {
		return status;
	}
	
	public void setStatus(Integer status) {
		this.status = status;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "USER_ID")
	public SysEmployee getUser() {
		return this.user;
	}

	public void setUser(SysEmployee user) {
		this.user = user;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "add_myaddr",joinColumns = { @JoinColumn(name = "group_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id", nullable = false, updatable = false) })
	public Set<AddMyaddr> getMyaddr() {
		return this.myaddr;
	}

	public void setMyaddr(Set<AddMyaddr> myaddr) {
		this.myaddr = myaddr;
	}

}